
/*
 * (C)opyright 2010, Alessandro Agosto. All rights reserved.
 * This file is part of the "pycoev" project.
 * To get more informations about the license read the LICENSE file.
 *
 * Module method to initialize the event library.
 */


#include "pyc_pyapis.h"
#include "pyc_event.h"


/*
 * "init" method.
 * @params: an integer representing the max number of file descriptors.
 * @return: Py_True on success, the right exception on failure.
 */
PyObject *
Pyc_Init(PyObject *unused, PyObject *args)
{
    int max_fds, res;

    res = PyArg_ParseTuple(args, "i:init", &max_fds);
    if (!res) {
        Pyc_Fatal(NULL, NULL);
    }

    res = picoev_init(max_fds);
    if (res == PYC_ERROR) {
        Pyc_Fatal(Pyc_Error,
                  "could not initialize picoev: there is not enough memory?");
    }

    Py_RETURN_TRUE;
}


PyObject *
Pyc_Deinit(void)
{
    if (!PICOEV_IS_INITED) {
        Pyc_Fatal(Pyc_Error, "the event library must be initialized");
    }

    picoev_deinit();

    Py_RETURN_NONE;
}
